/*
 * @lc app=leetcode.cn id=1275 lang=javascript
 *
 * [1275] 找出井字棋的获胜者
 */

// @lc code=start
/**
 * @param {number[][]} moves
 * @return {string}
 */
var tictactoe = function (moves) {
  const rowA = [0, 0, 0], colA = [0, 0, 0], diagA = [0, 0];
  const rowB = [0, 0, 0], colB = [0, 0, 0], diagB = [0, 0];
  for (let index = 0; index < moves.length; index++) {
    const [x, y] = moves[index];
    if (index % 2 === 0) {
      rowA[x]++;
      colA[y]++;
      if (rowA[x] === 3 || colA[y] === 3) return "A";
      if (x == y) {
        diagA[0]++;
        if (diagA[0] === 3) return "A";
      }
      if (x + y === 2) {
        diagA[1]++;
        if (diagA[1] === 3) return "A";
      }
    } else {
      rowB[x]++;
      colB[y]++;
      if (rowB[x] === 3 || colB[y] === 3) return "B";
      if (x == y) {
        diagB[0]++;
        if (diagB[0] === 3) return "B";
      }
      if (x + y === 2) {
        diagB[1]++;
        if (diagB[1] === 3) return "B";
      }
    }
  }
  return moves.length === 9 ? "Draw" : "Pending";
};
// @lc code=end

